<template>
  <div class="app-container">
    <el-form ref="noticeForm" :model="noticeData" label-width="120px">
      <!-- <el-form-item label="公告ID">
        <el-input v-model="noticeData.id" placeholder="请输入公告ID" :disabled="isEdit"></el-input>
      </el-form-item> -->
      <el-form-item label="公告标题">
        <el-input v-model="noticeData.title" placeholder="请输入公告标题"></el-input>
      </el-form-item>
      <el-form-item label="公告内容">
        <el-input type="textarea" v-model="noticeData.content" placeholder="请输入公告内容"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { insertNotice } from "@/api/notice";
export default {
  props: {
    isEdit: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      noticeData: {
        title: "",
        content: ""
        // status: 'active'
      },
    };
  },
  methods: {
    submitForm() {
      this.$refs.noticeForm.validate((valid) => {
        if (valid) {
          // 在这里处理表单提交逻辑，例如发送请求到后端API
          console.log("提交的公告数据:", this.noticeData);
          // 以下代码示例，实际应用中需要替换为API调用
          // this.saveNotice(this.noticeData);
          insertNotice(this.noticeData).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "新增成功",
                type: "success",
              });
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
            console.log(res);

            this.noticeData.title = "";
            this.noticeData.content = "";
          });
        } else {

          console.log("表单验证失败");
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.noticeForm.resetFields();
    },
  },
};
</script>

